<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
	var grid;

	$(function() {
		
		var menu;
		menu={
				url : sy.contextPath + '/principal/list',
				toolbar : '#toolbar',
				singleSelect : false,
				fitColumns:true,
				columns : [ [ {
					width : $(this).width() * 0.1,
					title : '机构概况',
					field : 'organizationInfo',
					align : 'center'
				},{
					width : $(this).width() * 0.1,
					title : '投资方式',
					field : 'info',
					align : 'center'
				},{
					width : $(this).width() * 0.1,
					title : '发布人',
					field : 'userId',
					align : 'center',
					formatter:function(v,r){
						if (r.nickName)
							return r.nickName+'('+r.account+')';
						return r.account;
					}
				}, 
				{
					width : $(this).width() * 0.15,
					title : '创建时间',
					field : 'createTime',
					align : 'center'
				},
				{
                    width : $(this).width()*0.05,
                    title : '状态',
                    field : 'isVerify',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(row.isVerify == 0){
                            return  '<a href="javascript:void(0);"  style="color:red" title="未审核">未审核</a>';
                        }else if(row.isVerify == 1){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/yes.png" title="审核通过" > </img></a>';
                        }else if(row.isVerify == 2){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/no.png" title="审核不通过" > </img></a>';
                        }
                    }
                }, 
				{
					width : $(this).width() * 0.15,
					title : '操作',
					field : 'ids',
					align : 'center',
					/* formatter:function(v,r){
						return '<a href="javascript:void(0);" onclick="detail(\''+r.id+'\',\''+r.organizationName+'\')" >查看详情</a>';
					} */
					formatter : function(value, row, index) {						
                        if(row.isVerify == 1 || row.isVerify == 2){                         
                            if(row.publishTime =='' || row.publishTime==null){
                				return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "tops(\''+row.isVerify+'\',\''+row.id+'\');">置顶</button>';
                			}else{
                				return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "cancelTops(\''+row.isVerify+'\',\''+row.id+'\');">取消置顶</button>';
                			}
                        }else if(row.isVerify == 0){
                            return '<a><button onclick="forbidden(1,\''+row.id+'\');">审核通过</button></a><a><button onclick="forbidden(2,\''+row.id+'\');">审核不通过</button></a>';
                        }
                        
                    }
				},
				{
                    width : $(this).width() * 0.15,
                    title : '查看',
                    field : 'check',
                    align : 'center',
                    formatter:function(v,r){
                        return '<a href="javascript:void(0);" onclick="detail(\''+r.id+'\')" >查看详情</a>';
                    }
                }
				] ]
			};
		
		grid = $('#grid').datagrid(menu);
		
		$('#isVerify').combobox({
			onChange:function(){
				grid.datagrid('load',sy.serializeObject($('#searchForm')));
			}
		});
	});
	
	var detail = function(id){
		parent.sy.modalDialog({
			title : '资本详情',
			width : 800,
			height : 600,
			url : sy.contextPath + '/go.do?path=ziben/detail&id=' + id
		});
	};
	
	 function updateByNotAgreeReason(id){
        var url = sy.contextPath +'/go.do?path=ziben/zibenNotAgreeReason&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '审核不通过原因',
            width : 800,
            height : 620,
            url : url,
            buttons : [ {
                text : '确认',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
   }
	
	function forbidden(state,id) {
		if (state == 1) {
			
			parent.$.messager.confirm('询问',"确定审核通过吗？", function(r) {
				if (r) {
					
					var data = {
						id : id,
						isVerify : 1
					};
					SaveData(data);
				}
			});
		} else if(state == 2){
			parent.$.messager.confirm('询问',"确定审核不通过吗？", function(r) {
				if (r) {
					var data = {
						id : id,
						isVerify : 2
					};
					updateByNotAgreeReason(id);
				}
			});
		}
	}
	function SaveData(data) {
		var url = sy.contextPath + '/principal/save';
		$.post(url, data, function() {
			grid.datagrid('reload');
		}, 'json');
	}
	var delFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择需要删除的记录！');
            return;
        }
        parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
            if (r) {
                var ids = [];
                for ( var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                
                $.post(sy.contextPath + '/principal/del.do', {
                    id : id
                }, function() {
                    rows.length = 0;//必须，否则有bug
                    grid.datagrid('reload');
                }, 'json');
            }
        });
    };
    
    
    function tops(isAgree,id){
    	if(isAgree==2){
    		$.messager.alert('Warning','审核未通过的不能置顶...');
    		return;
    	}
        var url = sy.contextPath + '/principal/top.do';
        var data={
                id: id
        }
        $.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json'); 
    }
    
    function cancelTops(isAgree,id){
  	   if(isAgree==2){
  		   $.messager.alert('Warning','审核未通过的不能置顶...');
  		   return;
  	   }
         var url = sy.contextPath + '/principal/cancelTops.do';
         var data={
                 id: id
         }
         $.post(url, data, function() {
             grid.datagrid('reload');
         }, 'json'); 
     }
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<table>
			<tr>
				<td>
					<form id="searchForm">
						<table>
							<tr>
								<td>机构名称：</td>
								<td>
									<input type="text" class="easyui-textbox" name="name" style="width: 150px"  />
								</td>
<!-- 								<td>审核状态:</td>
								<td>
									<select id='isVerify'  name='isVerify' editable='false' panelHeight='auto'>
										<option value='0'>全部</option>
										<option value='1'>待审核</option>
										<option value='2'>审核通过</option>
										<option value='3'>审核失败</option>
									</select>
								</td> -->
								<td>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>
							<!-- <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
							<td><div class="datagrid-btn-separator"></div></td>
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_edit',plain:true" onclick="editFun();">修改</a></td>
							-->
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>